package formbeans;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.mybeans.form.FormBean;

/*
 *  Course: S09-15437 - WEB APPLICATION DEVELOPMENT 
 * 	Name: Jiale Huang
 * 	Andrew ID: jialeh
 * 	Date: 2/23/2009
 *  Assignment: Hw4
 */

public class RegisterForm extends FormBean{
	
	private String userEmail;
	private String password;
	private String fName;
	private String lName;
	
	public String getUserEmail() {
		return userEmail;
	}
	public void setUserEmail(String userEmail) {
		this.userEmail = userEmail.trim();
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public void setFName(String name) {
		fName = name.trim();
	}
	public void setLName(String name) {
		lName = name.trim();
	}
	public String getLName() {
		return lName;
	}
	public String getFName() {
		return fName;
	}
	
    public List<String> getValidationErrors() {
        List<String> errors = new ArrayList<String>();
        
        if (userEmail == null || userEmail.length() == 0) errors.add("User Name is required");
        if (password == null || password.length() == 0) errors.add("Password is required");
        
        Pattern emailPattern = Pattern.compile("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?");
        Matcher matcher = emailPattern.matcher(userEmail);
        if (!matcher.matches()) errors.add("Invalid Format for E-mail Address");
        
        if (fName == null || fName.length() == 0) errors.add("First name is required");
        if (lName == null || lName.length() == 0) errors.add("Last name is required");

        if (userEmail.matches(".*[<>\"].*")) errors.add("User Name may not contain angle brackets or quotes");
        
        return errors;
    }



}
